<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" href="favicon.ico">
    <title>database - lamb</title>
    <link type="text/css" rel="stylesheet" href="/css/bootstrap.min.css">
    <link type="text/css" rel="stylesheet" href="/css/bootstrap-theme.min.css">
    <link type="text/css" rel="stylesheet" href="/css/blacklist.css">
  </head>
  <body>
    <div class="navbar navbar-default">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand">
            <img alt="Brand" src="/img/logo.png" width="32" height="32" style="margin-top:-6px" />
          </a>
          <a class="navbar-brand">lamb</a>
        </div>
        <div id="navbar" class="collapse navbar-collapse">
          <ul class="nav navbar-nav">
            <li><a href="/status/inbound">状态监控</a></li>
            <li><a href="/company">企业管理</a></li>
            <li><a href="/account">帐号管理</a></li>
            <li><a href="/template">签名模板</a></li>
            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button">路由管理</a>
              <ul class="dropdown-menu">
                <li><a href="/routing">上行路由</a></li>
                <li><a href="/delivery">下行路由</a></li>
              </ul>
            </li>
            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button">通道管理</a>
              <ul class="dropdown-menu">
                <li><a href="/gateway">落地通道</a></li>
                <li><a href="/gateway/report">通道数据统计</a></li>
                <li><a href="/gateway/check">通道测试</a></li>
              </ul>
            </li>
            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button">数据记录</a>
              <ul class="dropdown-menu">
                <li><a href="/message">上行短信</a></li>
                <li><a href="/message/deliver">下行短信</a></li>
                <li><a href="/message/statistic">数据统计</a></li>
              </ul>
            </li>
            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button">系统管理</a>
              <ul class="dropdown-menu">
                <li><a href="/keyword">关键词库</a></li>
                <li><a href="/payment/logs">充值记录</a></li>
                <li><a href="/service/core">服务状态</a></li>
              </ul>
            </li>
          </ul>
          <ul class="nav navbar-nav navbar-right">
            <li><a href="/logout"><span class="glyphicon glyphicon-log-out"></span> 退 出</a></li>
          </ul>
        </div>
      </div>
    </div>
    <div class="container">
      <div class="row">
        <ol class="breadcrumb">
          <li><a href="#">Home</a></li>
          <li class="active">Database</li>
          <li class="pull-right add"><a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="show()"><span class="glyphicon glyphicon-plus"></span> 创 建</a></li>
        </ol>
      </div>
      <div class="row">
        <table class="table table-hover">
          <thead>
            <tr><th>#</th><th>数据库名称</th><th>数据类型</th><th>号码数量</th><th>备注信息</th><th>查 询</th><th>删 除</th><th>操 作</th></tr>
          </thead>
          <tbody>
            <?php
              foreach ($databases as $d) {
               echo '<tr><td><span class="glyphicon glyphicon-paperclip"></span></td><td>',$d['name'],'</td>';
               echo '<td>',$d['type'] == 1 ? '黑名单' : '白名单','</td><td>',$d['total'],'</td><td>',$d['description'],'</td>';
               echo '<td><a class="btn btn-default btn-xs" href="#"><span class="glyphicon glyphicon-search"></span> 查 询</a></td>';
               echo '<td><a class="btn btn-default btn-xs"><span class="glyphicon glyphicon-trash"></span> 删 除</a></td><td>';
               echo '<div class="btn-group">';
               echo '<button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">操 作 <span class="caret"></span></button>';
               echo '<ul class="dropdown-menu">';
               echo '<li><a href="#">导入号码</a></li>';
               echo '<li><a href="#">导出号码</a></li>';
               echo '<li><a href="#">编辑数据库</a></li>';
               echo '<li><a href="#">删除数据库</a></li>';
               echo '</ul>';
               echo '</div>';
               echo '</td></tr>';
              }
            ?>
          </tbody>
        </table>
      </div>
    </div>
</div>
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/js/layer.js"></script>
<script type="text/javascript">
  $('li.dropdown').mouseover(function() {   
    $(this).addClass('open');
  }).mouseout(function() {
    $(this).removeClass('open');
  });

  function show() {
    var templete = '<form class="form-horizontal" action="/database/create" method="post" style="width:395px;margin-top:30px;margin-left:15px">'+
        '<div class="form-group">'+
        '<label class="col-sm-3 control-label">数据名称:</label>'+
        '<div class="col-sm-8">'+
        '<input type="text" class="form-control" name="name" placeholder="Enter name" minlength="3" required="required">'+
        '</div>'+
        '</div>'+
        '<div class="form-group">'+
        '<label class="col-sm-3 control-label">数据类型:</label>'+
        '<div class="col-sm-8">'+
        '<select class="form-control" name="type" required="required">'+
        '<option value="1">黑名单</option>'+
        '<option value="2">白名单</option>'+
        '</select>'+
        '</div>'+
        '</div>'+
        '<div class="form-group">'+
        '<label class="col-sm-3 control-label">备注信息:</label>'+
        '<div class="col-sm-8">'+
        '<input type="text" class="form-control" name="description" placeholder="Enter description">'+
        '</div>'+
        '</div>'+
        '<div class="form-group">'+
        '<div class="col-sm-offset-3 col-sm-8">'+
        '<button type="submit" class="btn btn-success">创 建</button><a href="javascript:void(0);" onClick="layer.closeAll()" class="btn btn-default" style="margin-left:15px">取 消</a>'+
        '</div>'+
        '</div>'+
        '</form>';

    layer.open({
      type: 1,
      title: '添加通道',
      area: ['425px', '285px'],
      content: templete
    });
  }
  
  function deletePhone(phone) {
    layer.confirm('亲，确定要将 ' + phone +  ' 号码删除？', {
      btn: ['是','否'], icon: 3
    }, function(){
      var url = '/security/delete?type=blacklist&phone=' + phone;
      $.get(url, function(){
        layer.msg('删除成功!', {icon: 1, time: 1000});
        setTimeout(function() {
          window.location.reload();
        }, 1000);
      });
    });
  }

  function query(type) {
    layer.prompt({title: '请输入要查询的号码', formType: 0}, function(phone, index) {
      layer.close(index);
        var url = '/security/check?type=' + type + '&phone=' + phone;
        $.get(url, function(resp, status) {
          if (resp.message == "yes") {
            layer.msg('号码 ' + phone + ' 已存在!', {icon: 1, time: 3000});
          } else {
            layer.msg('号码 ' + phone + ' 不存在!', {icon: 2, time: 3000});
          }
      });
    });
  }

  function phoneImport(type) {
    var text = '<div class="container" style="width:410px;height:200px;padding:40px 20px">' +
    '<form class="form-horizontal" action="/security/import" method="post" enctype="multipart/form-data">' +
      '<div class="form-group">' +
        '<div class="col-xs-3">' +
          '<label>号码文件:</label>' +
        '</div>' +
        '<div class="col-xs-8" style="margin-top:-5px">' +
          '<input type="hidden" class="form-control" name="type" value="' + type + '" />' +
          '<input type="file" class="form-control" name="file" placeholder="Enter number file" required="required">' +
        '</div>' +
      '</div>' +
      '<div class="form-group">' +
        '<div class="col-xs-offset-3 col-xs-7" style="margin-top:20px">' +
          '<button id="submit" type="submit" class="btn btn-success">提 交</button>' +
          '<button id="cancel" type="reset" style="margin-left:20px" class="btn btn-default" href="#">取 消</button>' +
          '</div>' +
      '</div>' +
      '</form>' +
    '</div>';

    layer.open({
      type: 1,
      title: '号码导入',
      area: ['440px', '250px'],
      content: text
    });
  }
</script>
</body>
</html>
